package tiltmaze.view;

import java.awt.Point;
import java.awt.Rectangle;

/**
 * Class used for storing the information about walls and checkpoints of the
 * graphical representation of the maze.
 * @author Juraj Niznan
 */
public class MazeRectangle extends Rectangle {

    public static final String VERTICAL_WALL = "verticalWall";
    public static final String HORIZONTAL_WALL = "horizontalWall";
    public static final String CHECKPOINT = "checkpoint";

    public boolean visible = true;
    public boolean hovered = false;
    private int row;
    private int col;
    private String type;

    private int border = MazeCanvas.BORDER;
    private int squareSize = MazeCanvas.SQUARE_SIZE;

    public MazeRectangle(int row, int col, String type) {
        super();
        if (type.equals(VERTICAL_WALL)) {
            x = border + col * 5 * squareSize;
            y = border + row * 5 * squareSize;
            width = squareSize;
            height = 6 * squareSize;
        }
        if (type.equals(HORIZONTAL_WALL)) {
            x = border + col * 5 * squareSize;
            y = border + row * 5 * squareSize;
            width = 6 * squareSize;
            height = squareSize;
        }
        if (type.equals(CHECKPOINT)) {
            x = border + (col * 5 + 2) * squareSize;
            y = border + (row * 5 + 2) * squareSize;
            width = 2 * squareSize;
            height = 2 * squareSize;
        }
        this.row = row;
        this.col = col;
        this.type = type;
    }

    @Override
    public boolean contains(Point p) {
        boolean ret = true;
        if (type.equals(HORIZONTAL_WALL)) {
            ret = ret && (x+height <= p.x) && (p.x <= x+width-height);
            ret = ret && (y <= p.y) && (p.y <= y+height);
        } else if (type.equals(VERTICAL_WALL)){
            ret = ret && (x <= p.x) && (p.x <= x+width);
            ret = ret && (y+width <= p.y) && (p.y <= y+height-width);
        } else {
            ret = super.contains(p);
        }
        return ret;
    }

    public int getCol() {
        return col;
    }

    public int getRow() {
        return row;
    }

    public String getType() {
        return type;
    }

    

}
